home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: The size of a file
- Date: Sun, 28 Jan 1996 01:13:00 GMT
- Organization: Netcom
- Message-ID: <310acacf.92393344@nntp.ix.netcom.com>
- References: <4ebc03$4gv@gate.compart.fi> <4edo88$4c7@news.xs4all.nl>
- NNTP-Posting-Host: ix-dc6-02.ix.netcom.com
- X-NETCOM-Date: Sat Jan 27 5:12:53 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- falstaff@xs4all.nl (Falstaff) wrote:
-
- > Fredrik Sandstrom <fred@spider.compart.fi> writes:
- >
- > >This is driving me nuts. I can't find a simple way to get the size of a
- > >disk file. This must be possible using the standard C library, but I
- > >haven't figured out how!
- >
- > f=fopen()
- > fseek(f,SEEK_END,0)
- > ftell(f)
- > fclose(f)
-
- This may not work.
-
- It's obvious that you intend this as an outline of the functions to
- call, not as an example of code and I am answering in that vein.
-
- The problem is that if the file is opened in text mode (fopen("file",
- "r") ftell() is not required to required to return a byte offset --
- it's value is unspecified (i.e., the implementation need not document
- it). It must, of course, be usable in fseek() to return to the
- current position. (ISO 7.9.9.4)
-
- This problem does not occur if the file is opened in binary mode
- (fopen("file", "rb")), but there we have the problem that the fseek()
- may not work as intended. "A binary stream need not meaningfully
- support fseek calls with a whence value of SEEK_END" (ISO 7.9.9.2).
-
- In practice this method does usually work, but if the implementation
- defines a (nonstandard) function for determining the size of the file
- I'd suggest considering it. stat() is a common name for such a
- function.
-
-
- Michael M Rubenstein
-